package org.oslims.client.uicomponents;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ErrorBox {

	private DialogBox errorBox = new DialogBox(false, true);
	private Label errorMessage = new Label();
	private Button okButton = new Button();

	public ErrorBox() {
		VerticalPanel errorBoxPanel = new VerticalPanel();
		HorizontalPanel buttonLine = new HorizontalPanel();
		buttonLine.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
		buttonLine.setWidth("100%");
		errorBoxPanel.add(errorMessage);

		okButton.setText("OK");
		errorBox.setText("Error");
		buttonLine.add(okButton);
		errorBoxPanel.add(buttonLine);

		okButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				errorBox.hide();
			}
		});

		errorBox.add(errorBoxPanel);
	}

	public void showError(String message) {
		errorMessage.setText(message);
		errorBox.center();
	}
}
